<?php

/**
 * Subclass for performing query and update operations on the 'contents' table.
 *
 *
 *
 * @package lib.model
 */
class ContentsPeer extends BaseContentsPeer{

    /******************************************************
     * VU時こはここを編集
     * ****************************************************/

    /// 指定されたIDのコンテンツの削除フラグ"n"の人のレコードを引っ張る ///
    static function getDat($content_id, $arr_delete_id){

        $c = new Criteria;

        switch($content_id){
            case "1":
                if($arr_delete_id){
                    foreach($arr_delete_id as $value){
                        $c->add(VwOnePeer::MEMBER_ID, $value, Criteria::NOT_EQUAL);
                    }
                }
                $arr_obj = VwOnePeer::doSelect($c);

                $y = 0;
                $arr = array();

                foreach($arr_obj as $v){
                    $val = (array)$v;

                    for($x=0; $x<2; $x++){
                        array_shift($val);
                    }
                    for($x=0; $x<6; $x++){
                        array_pop($val);
                    }
                    foreach($val as $va){
                        $arr[$y][] = $va;
                    }
                    $y++;
                }

                return $arr;
                break;

            case "2":
                if($arr_delete_id){
                    foreach($arr_delete_id as $value){
                        $c->add(VwTwoJeunoPeer::MEMBER_ID, $value, Criteria::NOT_EQUAL);
                    }
                }
                $arr_obj = VwTwoJeunoPeer::doSelect($c);

                $y = 0;
                $arr = array();

                foreach($arr_obj as $v){
                    $val = (array)$v;

                    for($x=0; $x<2; $x++){
                        array_shift($val);
                    }
                    for($x=0; $x<6; $x++){
                        array_pop($val);
                    }
                    foreach($val as $va){
                        $arr[$y][] = $va;
                    }
                    $y++;
                }

                return $arr;
                break;

            case "3":
                if($arr_delete_id){
                    foreach($arr_delete_id as $value){
                        $c->add(VwZilartPeer::MEMBER_ID, $value, Criteria::NOT_EQUAL);
                    }
                }
                $arr_obj = VwZilartPeer::doSelect($c);

                $y = 0;
                $arr = array();

                foreach($arr_obj as $v){
                    $val = (array)$v;

                    for($x=0; $x<2; $x++){
                        array_shift($val);
                    }
                    for($x=0; $x<6; $x++){
                        array_pop($val);
                    }
                    foreach($val as $va){
                        $arr[$y][] = $va;
                    }
                    $y++;
                }

                return $arr;
                break;

            case "4":
                if($arr_delete_id){
                    foreach($arr_delete_id as $value){
                        $c->add(VwThreePeer::MEMBER_ID, $value, Criteria::NOT_EQUAL);
                    }
                }
                $arr_obj = VwThreePeer::doSelect($c);

                $y = 0;
                $arr = array();

                foreach($arr_obj as $v){
                    $val = (array)$v;

                    for($x=0; $x<2; $x++){
                        array_shift($val);
                    }
                    for($x=0; $x<6; $x++){
                        array_pop($val);
                    }
                    foreach($val as $va){
                        $arr[$y][] = $va;
                    }
                    $y++;
                }

                return $arr;
                break;
        }
    }

    /// 指定されたIDのコンテンツのカラム名を取得 ///
    static function getTableHeader($content_id){

        switch($content_id){

            case "1":
                $arr_field_name = VwOnePeer::getFieldNames();
                array_shift($arr_field_name);
                unset($arr_field_name[0]);

                return $arr_field_name;
                break;

            case "2":
                $arr_field_name = VwTwoJeunoPeer::getFieldNames();
                array_shift($arr_field_name);
                unset($arr_field_name[0]);

                return $arr_field_name;
                break;

            case "3":
                $arr_field_name = VwZilartPeer::getFieldNames();
                array_shift($arr_field_name);
                unset($arr_field_name[0]);

                return $arr_field_name;
                break;

            case "4":
                $arr_field_name = VwThreePeer::getFieldNames();
                array_shift($arr_field_name);
                unset($arr_field_name[0]);

                return $arr_field_name;
                break;
        }
    }

    public function getContentIdName($arr_content_id){

        $c = new Criteria;

        foreach($arr_content_id as $value){

            $c->add(self::ID, $value);
        }
        $arr_obj = self::doSelect($c);

        $x = 0;
        foreach($arr_obj as $obj){

            $arr[$x][0] = $obj->getId();
            $arr[$x][1] = $obj->getContentName();
        }

        return $arr;
    }


    /******************************************************
     * ここまで
     * ****************************************************/


    ///// 渡されたidのコンテンツがあるか、削除フラグの状態チェック /////
    static function checkContent($content_id){

        $c = new Criteria;

        $c->add(self::ID, $content_id);
        $c->add(self::DELETE_FLG, "n");

        $arr_content = self::doSelect($c);

        $cnt = count($arr_content);

        if($cnt === 1){
            return true;
        }
        else{
            return false;
        }
    }


    /// IDと名前を配列で返す ///
    static function getRecords($content_id){

        $c = new Criteria;
        $c->add(MemberlistPeer::DELETE_FLG, "n");

        $arr_obj = MemberlistPeer::doSelect($c);

        $arr_delete_id = MemberlistPeer::getDeleteId();
        $arr_records = self::getDat($content_id, $arr_delete_id);

        $x = 0;

        foreach($arr_obj as $obj){
            $arr[$x][0] = $obj->getId();
            $arr[$x][1] = $obj->getName();

            $y = 2;

            foreach($arr_records[$x] as $value){
                $arr[$x][$y] = $value;
                $y++;
            }
            $x++;
        }
        return $arr;
    }

    /// 削除フラグの立っていないコンテンツIDを配列で返す ///
    static function getContentId(){

        $c = new Criteria;

        $c->add(self::DELETE_FLG, "n");
        $arr_content_id = self::doSelect($c);

        if($arr_content_id){

            return $arr_content_id;
        }
        else{

            return false;
        }
    }
}




















